package com.yanqu.road.server.logic.task.condition;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;

import java.math.BigInteger;
import java.util.List;

/**
 * 累计vip经验
 */
public class VipExpCondition extends BaseCondition {

	public VipExpCondition(TaskConditionInfo conditionInfo, BaseTaskData quest, BigInteger value, Object initArgs) {
		super(conditionInfo, quest, value, initArgs);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.VipExp.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.VipExp.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		BigInteger param4 = taskConditionInfo.getParamList().get(3);
		return getValue().compareTo(param4) >= 0;
	}

	@Override
	protected void changeValue(Object object) {
		//7.2.0需求：硬代码写死。存在activityType = 2，childType = 5的活动（原来最早的首充活动），才触发400028任务。start
		if (this.getTaskConditionInfo().getTaskId() == 400028) {
			List<ActivityInfo> activityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.RechargeActivity.getValue(), 5);
			if (activityList.isEmpty()) {
				return;
			}
		}
		//7.2.0需求：硬代码写死。存在activityType = 2，childType = 5的活动（原来最早的首充活动），才触发400028任务。start

		long value = (long) object;
		setValue(BigInteger.valueOf(value));
	}

}
